package com.aznest.controller;

import com.aznest.dto.CollectDTO;
import com.aznest.result.Result;
import com.aznest.entity.Collect;
import com.aznest.entity.Type;
import com.aznest.service.CollectService;
import com.aznest.vo.CollectVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 收藏信息表前端操作接口
 **/
@RestController
@RequestMapping("/collect")
@Api(tags = "收藏相关接口")
@Slf4j
public class CollectController {

    @Resource
    private CollectService collectService;

    /**
     * 添加收藏
     */
    @PostMapping("/add")
    @ApiOperation("添加收藏")
    public Result add(@RequestBody CollectDTO collect) {
        collectService.add(collect);
        return Result.success();
    }

    /**
     * 根据ID删除收藏
     */
    @DeleteMapping("/deleteByCollectId/{id}")
    @ApiOperation("根据ID删除收藏")
    public Result deleteByCollectId(@PathVariable Integer id) {
        collectService.deleteByCollectId(id);
        return Result.success();
    }

    /**
     * 根据用户ID查询收藏
     * @param userId
     * @return
     */
    @GetMapping("/selectByUserId/{userId}")
    @ApiOperation("根据用户ID查询收藏")
    public Result selectByUserId(@PathVariable Integer userId) {
        List<CollectVO> list = collectService.selectByUserId(userId);
        return Result.success(list);
    }

    /**
     * 根据用户ID和酒店ID查询收藏
     * @param userId
     * @param hotelId
     * @return
     */
    @GetMapping("/selectByUserIdAndHotelId")
    @ApiOperation("根据用户ID和酒店ID查询收藏")
    public Result selectByUserIdAndHotelId(@RequestParam Integer userId, @RequestParam Integer hotelId) {
        List<Collect> list = collectService.selectByUserIdAndHotelId(userId, hotelId);
        return Result.success(list);
    }
}
